home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0040_Copy File Routine.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  1.6 KB  |  58 lines

  1. unit FileUtil;
  2.  
  3. interface
  4.  
  5. procedure CopyFile( Source, Dest : string );
  6.  
  7. implementation
  8.  
  9. uses
  10.   WinTypes, SysUtils, Dialogs, LZExpand;
  11.  
  12.  
  13. procedure CopyFile( Source, Dest : string );
  14. var
  15.   SourceFile  : Integer;   { The LZ* functions use File Handles }
  16.   DestFile    : Integer;
  17.   RetCode     : Longint;
  18.   OpenFileBuf : TOFStruct;        { Record needed by LZOpenFile }
  19.   FileNameStz : array[ 0..255 ] of Char;
  20.   E           : EInOutError;   { Exception Object, just in case }
  21. begin
  22.   StrPCopy( FileNameStz, Source );
  23.   SourceFile := LZOpenFile( FileNameStz, OpenFileBuf, of_Read );
  24.  
  25.   if SourceFile < 0 then
  26.   begin
  27.     E := EInOutError.CreateFmt( 'Could not open %s', [ Source ] );
  28.     E.ErrorCode := SourceFile;
  29.     raise E;                               { Raise an Exception }
  30.   end;
  31.  
  32.   StrPCopy( FileNameStz, Dest );
  33.   DestFile := LZOpenFile( FileNameStz, OpenFileBuf, of_Create );
  34.  
  35.   if DestFile < 0 then
  36.   begin
  37.     LZClose( SourceFile );       { Be sure to close Source File }
  38.     E := EInOutError.CreateFmt( 'Could not create %s', [ Dest ] );
  39.     E.ErrorCode := DestFile;
  40.     raise E;                               { Raise an Exception }
  41.   end;
  42.  
  43.   RetCode := LZCopy( SourceFile, DestFile );
  44.  
  45.   LZClose( SourceFile );             { Even if LZCopy fails, we }
  46.   LZClose( DestFile );             { still must close the files }
  47.  
  48.   if RetCode < 0 then
  49.   begin
  50.     E := EInOutError.CreateFmt( 'Could not copy %s to %s',
  51.                                 [ Source, Dest ] );
  52.     E.ErrorCode := RetCode;
  53.     raise E;                               { Raise an Exception }
  54.   end;
  55. end; {= CopyFile =}
  56.  
  57. end.
  58.